using UnityEngine;
using System.Collections;

/// \class  gkAbyssalGiantRockExplosionComponent
/// \brief  Handle the rock explosion creation
[AddComponentMenu("GK/AbyssalGiant/Rock/gkAbyssalGiantRockExplosionComponent")]
public class gkAbyssalGiantRockExplosionComponent : MonoBehaviour 
{
	/// The explosion
	public GameObject Explosion;
	
	/// \brief  Called when the component is enabled
	void OnEnable() 
	{
		// Listen the shock event of the owner
		GetComponent<gkEventComponent>().AddEventHandler(gkAbyssalGiantExplosionEvent.Explosion, HandleExplosionEvent);
	}
	
	/// \brief  Called when the component is disabled
	void OnDisable() 
	{	
		// Remove the shock event of the owner
		GetComponent<gkEventComponent>().RemoveEventHandler(gkAbyssalGiantExplosionEvent.Explosion, HandleExplosionEvent);
	}
	
	/// Handle the boost event
	void HandleExplosionEvent(Object a_rEvent)
	{
		GameObject rCreatedExplosion;
		
		// Spawn explosion
		rCreatedExplosion = Instantiate(Explosion) as GameObject;
		rCreatedExplosion.transform.position = transform.position;
		rCreatedExplosion.transform.rotation = transform.rotation;
		rCreatedExplosion.transform.localScale = transform.localScale;
	}
}
